//倒计时函数
import { ref, computed, onUnmounted } from 'vue'
import dayjs from 'dayjs'
export const useCountDown = () => {
  let timeId = null
  const time = ref()
  const formatTime = computed(() => dayjs.unix(time.value).format('mm分ss秒'))
  const start = (currentTime) => {
    time.value = currentTime
    timeId = setInterval(() => { time.value-- }, 1000)
  }
  onUnmounted(() => { timeId && clearInterval(timeId) })
  return { formatTime, start }
}
